package com.mystore.util;

import java.util.List;

/**
 * 分页工具类
 * @param <T>
 */
public class PageUtil<T> {
    //每页的大小
    private int pageSize;
    //页面数
    private int pageNumber;
    //总记录数
    private int pageTotal;

    private List<T> list;

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    /**
     * 首页
     * @return
     */
    public int headPage(){
        return 1;
    }

    /**
     * 上一页
     * @return
     */
    public int prePage(){
        //判断是否是首页
        if(pageNumber>1) {
            return pageNumber-1;
        }
        return pageNumber;
    }


    public int totalPage(){
        int total = pageTotal%pageSize;
        if(total==0){
            return pageTotal/pageSize;
        }else{
            return pageTotal/pageSize+1;
        }

    }
    public int nextPage(){
        int total  = totalPage();
        if(pageNumber>=total){
            return total;
        }
        return pageNumber+1;
    }

    public int lastPage(){
        return totalPage();
    }
}
